/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.annotation.Resource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.apache.log4j.Logger;

/**
 *
 * @author Insect
 */
public class SQLConnection {

    private InitialContext context ;
    private Context env;
    private PreparedStatement pstmt;
    private Logger myLogger = Logger.getLogger("RootLogger");
    
    @Resource(authenticationType=javax.annotation.Resource.AuthenticationType.CONTAINER, name="jdbc/TimeSheetDS", type=javax.sql.DataSource.class)
    private DataSource ds;
    public Connection getMySQLConnection() throws Exception{
        myLogger.info("Entering..");
        Connection connection;
        context = new InitialContext();
        env = (Context)context.lookup("java:comp/env");
        ds = (DataSource)env.lookup("jdbc/TimeSheetDS");
        connection = ds.getConnection();
        myLogger.info("Exiting..");
        return connection;
    }
}
